/*
 * Copyright FUOC.  All rights reserved.

 */
package managedbean;

import java.io.Serializable;
import java.util.Properties;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.naming.Context;
import javax.naming.InitialContext;

import jpa.CustomerJPA;
import ejb.CustomerFacadeRemote;

/**
 * Managed Bean ShowClientMBean
 */
@ManagedBean(name = "customershow")
@SessionScoped
public class ShowClientMBean implements Serializable{
	
	private static final long serialVersionUID = 1L;

	@EJB
	private CustomerFacadeRemote customerRemote;

	protected CustomerJPA dataCustomer = new CustomerJPA();
	
	protected String nifCustomer=null;
	
	
	public ShowClientMBean() throws Exception 
	{
		showCustomerMBean();
	}
	
	public ShowClientMBean(String id) throws Exception 
	{
		setNifCustomer(id);
	}
	
	public String index() throws Exception {
		nifCustomer = null;
		return "homeView";
	}
	public String back1() throws Exception {
		nifCustomer = null;
		return "ClientListView";
	}
	
	/**
	 * NifCustomer Getter and setter
	 */
	public String getNifCustomer(){
		return this.nifCustomer;
	}
	public void setNifCustomer(String nifCustomer) throws Exception{
		this.nifCustomer = nifCustomer;
		showCustomerMBean();
	}
	
	/**
	 * DataCustomer Getter and setter
	 */
	public CustomerJPA getDataCustomer()
	{
		return dataCustomer;
	}
	
	public void setDataCustomer(CustomerJPA customer){
		this.dataCustomer = customer;
	}
	
	/**
	 * Method to prepare data to show customer
	 * @throws Exception 
	 */
	public void showCustomerMBean() throws Exception{
		showCustomer();
	}
	
	/**
	 * Method to show a customer
	 */
	public void showCustomer() throws Exception{
		Properties props = System.getProperties();
		Context ctx = new InitialContext(props);
		customerRemote = (CustomerFacadeRemote) ctx.lookup("java:app/PracticalCaseStudyJEE.jar/CustomerFacadeBean!ejb.CustomerFacadeRemote");
		dataCustomer = (CustomerJPA) customerRemote.showCustomer(nifCustomer);
		dataCustomer = customerRemote.showCustomer(nifCustomer);
	}
	
}
